package com.qifan.alb2b.action.front;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qifan.alb2b.domain.CountryInfoDomain;
import com.qifan.alb2b.service.CityInfoService;
import com.qifan.alb2b.service.cache.AppCache;

@Controller
@RequestMapping("/city")
public class CityController {
	private CityInfoService cityInfoService;

	public void setCityInfoService(CityInfoService cityInfoService) {
		this.cityInfoService = cityInfoService;
	}
	
	/**
	 * 根据国家id查询所有的城市
	 * @param request
	 * @param countryId
	 * @return
	 */
	@RequestMapping("/queryCityByCountry.usr")
	public String queryCityByCountry(HttpServletRequest request,String countryId,int type){
		CountryInfoDomain country=null;
		List<CountryInfoDomain> list= AppCache.countryInfoList;
		for(int i=0;i<list.size();i++){
			if(list.get(i).getCountryId().equals(countryId)){
				country=list.get(i);
				break;
			}
		}
		request.setAttribute("citys", cityInfoService.queryCityByCountry(countryId));
		request.setAttribute("type", type);
		request.getSession(true).setAttribute("countryName", country.getCountryCm());
		return "pages/front/country_city";
	}
}
